package com.smart.village.big.screen.controller.micro;

import com.alibaba.fastjson.JSONObject;
import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.domain.SendMessage;
import com.smart.village.big.screen.service.WxMPService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

@Tag(name = "微信服务号推送消息")
@RestController
@RequestMapping("/wx/mp")
public class WxMPController {
    Logger logger = Logger.getLogger(WxMPController.class.getName());

    @Autowired
    private WxMPService wxMPService;

    @Operation(summary = "发送模板消息")
    @PostMapping("/sendTemplateMessage")
    @ResponseBody
    public AjaxResult sendTemplateMessage(@RequestBody @Validated SendMessage sendMessage) {
        try {
            logger.info("sendTemplateMessage,  sendMessage: {"+ sendMessage.toString() +"}");
            return AjaxResult.success(wxMPService.sendTemplateMessage(sendMessage));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendTemplateMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }
    @Operation(summary = "发送模板消息-小程序模板")
    @PostMapping("/sendMicroProgramTemplateMessage")
    @ResponseBody
    public AjaxResult sendMicroProgramTemplateMessage(@RequestBody @Validated SendMessage sendMessage) {
        try {
            logger.info("sendTemplateMessage,  sendMessage: {"+ sendMessage.toString() +"}");
            return AjaxResult.success(wxMPService.sendMicroProgramTemplateMessage(sendMessage));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendTemplateMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }


    @Operation(summary = "发送-活动提醒")
    @GetMapping("/sendActivityMessage")
    @ResponseBody
    public AjaxResult sendActivityMessage(@RequestParam("Member") String Member, @RequestParam("Data") String Data) {
        try {
            logger.info("sendActivityMessage,  Member: {"+ Member +"}, data: {"+ Data +"}");
            return AjaxResult.success(wxMPService.sendActivityMessage(Member, Data));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendActivityMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }
    @Operation(summary = "发送-党费提醒")
    @GetMapping("/sendPartyFeeMessage")
    @ResponseBody
    public AjaxResult sendPartyFeeMessage( @RequestParam("Data") String Data,@RequestParam(value = "Msg",required = false) String Msg) {
        try {
            logger.info("sendPartyFeeMessage,  Data: {"+ Data +"}, Msg: {"+ Msg +"}");
            return AjaxResult.success(wxMPService.sendPartyFeeMessage(Data,Msg));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendPartyFeeMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }
    @Operation(summary = "发送-事件提醒")
    @GetMapping("/sendComplaintsMessage")
    @ResponseBody
    public AjaxResult sendComplaintsMessage( @RequestParam("Data") String Data) {
        try {
            logger.info("sendComplaintsMessage,  Data: {"+ Data +"}");
            return AjaxResult.success(wxMPService.sendComplaintsMessage(Data));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendComplaintsMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }

    @Operation(summary = "发送-网格任务未完成提醒")
    @GetMapping("/sendGridTaskMessage")
    @ResponseBody
    public AjaxResult sendGridTaskMessage( ) {
        try {
            logger.info("sendGridTaskMessage ---begin---");
            return AjaxResult.success(wxMPService.sendGridTaskMessage());
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendGridTaskMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }

    @Operation(summary = "发送-巡边任务未完成提醒")
    @GetMapping("/sendPatrolTaskMessage")
    @ResponseBody
    public AjaxResult sendPatrolTaskMessage( ) {
        try {
            logger.info("sendPatrolTaskMessage ---begin---");
            return AjaxResult.success(wxMPService.sendPatrolTaskMessage());
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendPatrolTaskMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }

    @Operation(summary = "发送-帮办待办提醒")
    @GetMapping("/sendHelpMessage")
    @ResponseBody
    public AjaxResult sendHelpMessage( @RequestParam("Data") String Data) {
        try {
            logger.info("sendHelpMessage,  Data: {"+ Data +"}");
            return AjaxResult.success(wxMPService.sendHelpMessage(Data));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("sendHelpMessage  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }

    @Operation(summary = "校验服务")
    @GetMapping("/Authorization_Service")
    @ResponseBody
    public AjaxResult Authorization_Service( @RequestParam("Data") String Data) {
        try {
            logger.info("Authorization_Service,  Data: {"+ Data +"}");
            return AjaxResult.success(wxMPService.Authorization_Service(Data));
        }catch (Exception e){
            e.printStackTrace();
            logger.severe("Authorization_Service  error: " + e.getMessage());
            return AjaxResult.error(e.getMessage());
        }

    }
}
